<?php
require('functions/page_load.php');
require("fckeditor/fckeditor.php");

$content_nav = true;

if($_SERVER['REQUEST_METHOD'] == 'POST'){

$sql = "UPDATE faqs SET question = '".mysql_real_escape_string($_POST['question'])."', answer = '".mysql_real_escape_string($_POST['answer'])."', tradesman = '".mysql_real_escape_string($_POST['tradesman'])."', user = '".mysql_real_escape_string($_POST['user'])."' WHERE id = '".mysql_real_escape_string($_GET['id'])."'";
$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());

$results = '<div class="success_result">FAQ updated successfully!</div>';

}

$results = ($_GET['new'] == 'true') ? '<span class="success_result" style="margin-bottom: 10px;">FAQ successfully created.</span>' : $results ;

$sql = "SELECT question, answer, tradesman, user FROM faqs WHERE id = '".$_GET['id']."'";
$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
$rs = mysql_fetch_assoc($query);

require('includes/header.php');
?>

<div class="side_container">
<h2 class="container_header">Navigation</h2>

<ul>
<li><a href="content.php">Pages</a></li>
<li><a href="blog.php">Blog</a></li>
<li><a href="directory.php">Directory</a></li>
<li><a href="faqs.php">FAQs</a></li>
</ul>

</div>

<div class="main_container_wrapper">

	<div class="main_container">
	<h2 class="container_header">Edit FAQ</h2>
	
	<?php echo $results; ?>
	
	<form method="post" action="">

	
	<div class="form_row_wrapper">
	<div class="form_row_left"><label for="question">Question:</label></div>
	<div class="form_row_right"><input type="text" name="question" id="question" value="<?php echo $rs['question']; ?>" style="width: 400px;" class="textbox" /></div>
	</div>

	<div class="form_row_wrapper">
	<div class="form_row_left"><label>Answer:</label></div>
	<div class="form_row_right">
	<?php
	$oFCKeditor = new FCKeditor('answer');
	$oFCKeditor->Height = '400';
	$oFCKeditor->BasePath = '/admin/fckeditor/';
	$oFCKeditor->Value = $rs['answer'];
	$oFCKeditor->Create();
	?>
	</div>
	</div>
	
	<div class="form_row_wrapper">
	<div class="form_row_left"><label for="tradesman">Tradesman FAQ:</label></div>
	<div class="form_row_right"><input type="checkbox" name="tradesman" id="tradesman" value="1"<?php echo ($rs['tradesman'] == '1') ? ' checked="checked"' : '' ; ?> /><span style="margin-left: 10px;">Display in tradesman FAQ's.</span></div>
	</div>
	
	<div class="form_row_wrapper">
	<div class="form_row_left"><label for="user">User FAQ:</label></div>
	<div class="form_row_right"><input type="checkbox" name="user" id="user" value="1"<?php echo ($rs['user'] == '1') ? ' checked="checked"' : '' ; ?> /><span style="margin-left: 10px;">Display in user FAQ's.</span></div>
	</div>
	
	<div class="form_row_wrapper">
	<div class="form_row_left">&nbsp;</div>
	<div class="form_row_right"><input type="image" src="images/save_button.png" alt="Save" /></div>
	</div>
	
	</form>

	</div>

</div>
	
<?php
	require('includes/footer.php');
?>